import { defHttp } from '/@/utils/http/axios';

enum Api {
  GenTablePageApi = '/gen/table/page',
  GenTableDetailApi = '/gen/table/detail',
  GenTableEditApi = '/gen/table/edit',
  GenTableDeleteApi = '/gen/table/delete',
  GetSelectTableApi = '/gen/table/select',
  ImportGenTableApi = '/gen/table/import',
  GenTablePreviewApi = '/gen/table/preview',

  GenTableFieldPageApi = '/gen/table/field/page',
  DownloadApi = '/gen/table/download',
  BatchDelGenTableApi = '/gen/table/batch-del',
}

interface GenTableVO {
  tableId?: string
}

/**
 * @description: 获取代码生成表分页数据
 */
export const getGenTablePage = (params: object) => {
  return defHttp.post({ url: Api.GenTablePageApi, params });
};

/**
 * @description: 获取代码生成表分页数据
 */
export const getGenTableFieldPage = (params: String) => {
  return defHttp.post({ url: Api.GenTableFieldPageApi, params });
};

/**
 * @description: 获取业务表分页数据
 */
export const getSelectTablePage = (params: object) => {
  return defHttp.post({ url: Api.GetSelectTableApi, params });
};

/**
 * @description: 查询代码生成表详细信息
 */
export const getGenTableInfo = (params: string) => {
  return defHttp.post({ url: Api.GenTableDetailApi, params });
};

/**
 * @description: 导入业务表
 */
export const importTable = (params: object) => {
  return defHttp.post({ url: Api.ImportGenTableApi, params });
};

/**
 * @description: 预览代码
 */
export const previewApi = (tableId: string) => {
  const data: GenTableVO = {
    tableId: tableId
  };
  return defHttp.post({ url: Api.GenTablePreviewApi, data });
};

/**
 * @description: 下载代码
 */
export const download = (params: object) => {
  return defHttp.post(
    { url: Api.DownloadApi, params, responseType: 'blob' },
    { isReturnNativeResponse: true },
  );
};

/**
 * @description: 修改代码生成表
 */
export const updateGenTable = (params: object) => {
  return defHttp.post({ url: Api.GenTableEditApi, params });
};

/**
 * @description: 删除代码生成表
 */
export const delGenTable = (tableId: string) => {
  const data: GenTableVO = {
    tableId: tableId
  };
  return defHttp.post({ url: Api.GenTableDeleteApi, data });
};

/**
 * @description: 批量删除代码生成表
 */
export const batchDelGenTable = (params: object) => {
  return defHttp.post({ url: Api.BatchDelGenTableApi, params });
};
